package com.openbravo.editor;

import com.openbravo.basic.BasicException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;

public abstract class JEditorText extends JEditorAbstract
{
  protected String m_svalue = null;
  public static final int MODE_Abc1 = 0;
  public static final int MODE_abc1 = 1;
  public static final int MODE_ABC1 = 2;
  public static final int MODE_123 = 3;
  public int m_iMode = getStartMode();
  protected int m_iTicks = 0;
  protected char m_cLastChar = '\000';
  protected long m_lcount = 0L;
  private Timer m_jtimer = new Timer(1000, new TimerAction( ));
  private static final char[] CHAR_abc1_1 = { '.', '?', '!', ',', '1', ';', ':' };
  private static final char[] CHAR_abc1_2 = { 'a', 'b', 'c', '2', ' ' };
  private static final char[] CHAR_abc1_3 = { 'd', 'e', 'f', '3', '‚' };
  private static final char[] CHAR_abc1_4 = { 'g', 'h', 'i', '4', '¡' };
  private static final char[] CHAR_abc1_5 = { 'j', 'k', 'l', '5' };
  private static final char[] CHAR_abc1_6 = { 'm', 'n', 'o', '6', '¤', '¢' };
  private static final char[] CHAR_abc1_7 = { 'p', 'q', 'r', 's', '7' };
  private static final char[] CHAR_abc1_8 = { 't', 'u', 'v', '8', '£', 65533 };
  private static final char[] CHAR_abc1_9 = { 'w', 'x', 'y', 'z', '9' };
  private static final char[] CHAR_abc1_0 = { ' ', '0' };
  private static final char[] CHAR_ABC1_1 = { '.', '?', '!', ',', '1', ';', ':' };
  private static final char[] CHAR_ABC1_2 = { 'A', 'B', 'C', '2', 'µ' };
  private static final char[] CHAR_ABC1_3 = { 'D', 'E', 'F', '3', 'É' };
  private static final char[] CHAR_ABC1_4 = { 'G', 'H', 'I', '4', 'Í' };
  private static final char[] CHAR_ABC1_5 = { 'J', 'K', 'L', '5' };
  private static final char[] CHAR_ABC1_6 = { 'M', 'N', 'O', '6', 'Ñ', 'Ó' };
  private static final char[] CHAR_ABC1_7 = { 'P', 'Q', 'R', 'S', '7' };
  private static final char[] CHAR_ABC1_8 = { 'T', 'U', 'V', '8', 'Ú', 'Ü' };
  private static final char[] CHAR_ABC1_9 = { 'W', 'X', 'Y', 'Z', '9' };
  private static final char[] CHAR_ABC1_0 = { ' ', '0' };

  public JEditorText()
  {
    this.m_jtimer.start();
  }

  protected abstract int getStartMode();

  public final void reset()
  {
    String str = getText();
    this.m_iMode = getStartMode();
    this.m_svalue = null;
    this.m_iTicks = 0;
    this.m_cLastChar = '\000';
    reprintText();
    firePropertyChange("Text", str, getText());
  }

  public final void setText(String paramString)
  {
    String str = getText();
    this.m_svalue = paramString;
    this.m_iTicks = 0;
    this.m_cLastChar = '\000';
    reprintText();
    firePropertyChange("Text", str, getText());
  }

  public final void setEditModeEnum(int paramInt)
  {
    this.m_iMode = paramInt;
    this.m_iTicks = 0;
    this.m_cLastChar = '\000';
    reprintText();
  }

  public final String getText()
  {
    if (this.m_cLastChar == 0)
      return this.m_svalue;
    return appendChar2Value(getKeyChar());
  }

  protected final int getAlignment()
  {
    return 2;
  }

  protected final String getEditMode()
  {
    switch (this.m_iMode)
    {
    case 0:
      return "Abc1";
    case 1:
      return "abc1";
    case 2:
      return "ABC1";
    case 3:
      return "123";
    }
    return null;
  }

  protected String getTextEdit()
  {
    StringBuffer localStringBuffer = new StringBuffer();
    localStringBuffer.append("<html>");
    if (this.m_svalue != null)
      localStringBuffer.append(this.m_svalue);
    if (this.m_cLastChar != 0)
    {
      localStringBuffer.append("<font color=\"#a0a0a0\">");
      localStringBuffer.append(getKeyChar());
      localStringBuffer.append("</font>");
    }
    localStringBuffer.append("<font color=\"#a0a0a0\">_</font>");
    return localStringBuffer.toString();
  }

  protected String getTextFormat()
    throws BasicException
  {
    return "<html>" + this.m_svalue;
  }

  protected void typeCharInternal(char paramChar)
  {
    String str = getText();
    if (paramChar == '\b')
    {
      if (this.m_cLastChar == 0)
      {
        if ((this.m_svalue != null) && (this.m_svalue.length() > 0))
          this.m_svalue = this.m_svalue.substring(0, this.m_svalue.length() - 1);
      }
      else
      {
        this.m_iTicks = 0;
        this.m_cLastChar = '\000';
      }
    }
    else if (paramChar == '')
    {
      this.m_iMode = getStartMode();
      this.m_svalue = null;
      this.m_iTicks = 0;
      this.m_cLastChar = '\000';
    }
    else if (paramChar >= ' ')
    {
      if (this.m_cLastChar != 0)
      {
        char c = getKeyChar();
        this.m_svalue = appendChar2Value(c);
        acceptKeyChar(c);
      }
      this.m_iTicks = 0;
      this.m_cLastChar = '\000';
      this.m_svalue = appendChar2Value(paramChar);
    }
    this.m_jtimer.restart();
    firePropertyChange("Text", str, getText());
  }

  protected void transCharInternal(char paramChar)
  {
    String str = getText();
    if (paramChar == '-')
    {
      if (this.m_cLastChar == 0)
      {
        if ((this.m_svalue != null) && (this.m_svalue.length() > 0))
          this.m_svalue = this.m_svalue.substring(0, this.m_svalue.length() - 1);
      }
      else
      {
        this.m_iTicks = 0;
        this.m_cLastChar = '\000';
      }
    }
    else if (paramChar == '')
    {
      this.m_iMode = getStartMode();
      this.m_svalue = null;
      this.m_iTicks = 0;
      this.m_cLastChar = '\000';
    }
    else if (paramChar == '.')
    {
      if (this.m_cLastChar != 0)
        this.m_svalue = appendChar2Value(getKeyChar());
      this.m_iTicks = 0;
      this.m_cLastChar = '\000';
      this.m_iMode = ((this.m_iMode + 1) % 4);
    }
    else if ((paramChar == '1') || (paramChar == '2') || (paramChar == '3') || (paramChar == '4') || (paramChar == '5') || (paramChar == '6') || (paramChar == '7') || (paramChar == '8') || (paramChar == '9') || (paramChar == '0'))
    {
      if (this.m_iMode == 3)
      {
        this.m_svalue = appendChar2Value(paramChar);
      }
      else if (paramChar == this.m_cLastChar)
      {
        this.m_iTicks += 1;
      }
      else
      {
        if (this.m_cLastChar != 0)
        {
          char c = getKeyChar();
          this.m_svalue = appendChar2Value(c);
          acceptKeyChar(c);
        }
        this.m_iTicks = 0;
        this.m_cLastChar = paramChar;
      }
    }
    this.m_jtimer.restart();
    firePropertyChange("Text", str, getText());
  }

  private void acceptKeyChar(char paramChar)
  {
    if ((this.m_iMode == 0) && (paramChar != ' '))
      this.m_iMode = 1;
    else if ((this.m_iMode == 1) && (paramChar == '.'))
      this.m_iMode = 0;
  }

  protected char getKeyChar()
  {
    char[] arrayOfChar = null;
    switch (this.m_iMode)
    {
    case 1:
      switch (this.m_cLastChar)
      {
      case '1':
        arrayOfChar = CHAR_abc1_1;
        break;
      case '2':
        arrayOfChar = CHAR_abc1_2;
        break;
      case '3':
        arrayOfChar = CHAR_abc1_3;
        break;
      case '4':
        arrayOfChar = CHAR_abc1_4;
        break;
      case '5':
        arrayOfChar = CHAR_abc1_5;
        break;
      case '6':
        arrayOfChar = CHAR_abc1_6;
        break;
      case '7':
        arrayOfChar = CHAR_abc1_7;
        break;
      case '8':
        arrayOfChar = CHAR_abc1_8;
        break;
      case '9':
        arrayOfChar = CHAR_abc1_9;
        break;
      case '0':
        arrayOfChar = CHAR_abc1_0;
      }
      break;
    case 0:
    case 2:
      switch (this.m_cLastChar)
      {
      case '1':
        arrayOfChar = CHAR_ABC1_1;
        break;
      case '2':
        arrayOfChar = CHAR_ABC1_2;
        break;
      case '3':
        arrayOfChar = CHAR_ABC1_3;
        break;
      case '4':
        arrayOfChar = CHAR_ABC1_4;
        break;
      case '5':
        arrayOfChar = CHAR_ABC1_5;
        break;
      case '6':
        arrayOfChar = CHAR_ABC1_6;
        break;
      case '7':
        arrayOfChar = CHAR_ABC1_7;
        break;
      case '8':
        arrayOfChar = CHAR_ABC1_8;
        break;
      case '9':
        arrayOfChar = CHAR_ABC1_9;
        break;
      case '0':
        arrayOfChar = CHAR_ABC1_0;
      }
    }
    if (arrayOfChar == null)
      return this.m_cLastChar;
    return arrayOfChar[(this.m_iTicks % arrayOfChar.length)];
  }

  private String appendChar2Value(char paramChar)
  {
    StringBuffer localStringBuffer = new StringBuffer();
    if (this.m_svalue != null)
      localStringBuffer.append(this.m_svalue);
    localStringBuffer.append(paramChar);
    return localStringBuffer.toString();
  }

  private class TimerAction
    implements ActionListener
  {
    private TimerAction()
    {
    }

    public void actionPerformed(ActionEvent paramActionEvent)
    {
      if (JEditorText.this.m_cLastChar != 0)
      {
        char c = JEditorText.this.getKeyChar();
        JEditorText.this.m_svalue = JEditorText.this.appendChar2Value(c);
        JEditorText.this.acceptKeyChar(c);
        JEditorText.this.m_iTicks = 0;
        JEditorText.this.m_cLastChar = '\000';
        JEditorText.this.m_jtimer.restart();
        JEditorText.this.reprintText();
      }
    }
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.editor.JEditorText
 * JD-Core Version:    0.6.0
 */